$(function(){
	$(".coll_body").eq(1).show();
	$(".coll_body").eq(1).children('a').eq(2).addClass("active");
	$(".Collapsing").eq(1).children('a').children('span').addClass("rotate");
	$(".Collapsing").eq(1).click(function(){
		$(".Collapsing").eq(1).toggleClass("active");
		$(this).children('.coll_body').children('a').eq(2).toggleClass("active");
	})
//	获取url传值
	function getQueryString(name) {
		var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
		if (result == null || result.length < 1) {return "";}
			return result[1];
		}
		sid = getQueryString("sid");
//	获取签约列表信息
	$.ajax({
		type:"post",
		url:serverIP+"/user/signMethod/list",
		dataType:"json",
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
		success:function (data) {
			let result=data.data.list.result;
			var strVar = "";
			result.map(function(u){
				if(u.signMethodId==sid){
					$('input[name="name"]').val(u.name);
					$('input[name="monoSinglePrice"]').val(u.monoSinglePrice);
					$('input[name="colorSinglePrice"]').val(u.colorSinglePrice);
					$('input[name="papeNum"]').val(u.papeNum);
					var finishDate=u.finishDate.slice(0,10);
					$('input[name="finishDate"]').val(finishDate);
					if(u.payMethod==""){
						$('[name="payMethod"] option:first').prop("selected",'selected');
					}else if(u.payMethod==03){
						$('[name="payMethod"] option:nth-child(2)').prop("selected",'selected');
					}else if(u.payMethod==02){
						$('[name="payMethod"] option:nth-child(3)').prop("selected",'selected');
					}else if(u.payMethod==01){
						$('[name="payMethod"] option:nth-child(4)').prop("selected",'selected');
					}
					if(u.status==01){
						$('[name="status"] option:first').prop("selected",'selected');
					}else{
						$('[name="status"] option:last').prop("selected",'selected');
					}
					$('input[name="deposit"]').val(u.deposit);
					$('input[name="other"]').val(u.other);
				}
			})
		}
	})
})
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
}

$.validator.setDefaults({
    submitHandler: function() {
      	var params = $(".form-div").serialize()+'&signMethodId='+sid; 
      	$.ajax( {  
                type : "POST",  
                url : serverIP+"/user/signMethod/save",  
                data : params,  
                xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
                success : function(data) {
                	if(data.code==0){
                		alert("修改签约方式成功");
                	}else{
                		alert(data.msg);
                	}
                }    
            }); 
    }
});

$(document).ready(function() {
	$('.form-div').validate({
		rules: {
		 	name: "required",
		 	monoSinglePrice: {
		 		required: true,
		 		number:true
		 	},
		 	colorSinglePrice:{
		 		required: true,
				number:true
		 	},
		 	deposit:{
		 		required: true,
				number:true
		 	}
		},
		messages: {
	      	name: "请输入租户的名字",
	      	monoSinglePrice: {
	       		required: "请输入黑白纸张单价(元)",
	        	number: "请输入数字"
	      	},
	      	colorSinglePrice: {
	        	required: "请输入彩色纸张单价(元)",
	        	number: "请输入数字"
	      	},
	      	deposit: {
	        	required: "请输入押金",
	        	number: "请输入数字"
	      	}
		}	
	})
	
})
//时间插件
$('#finishTime').each(function() {
	var a = new Calendar({
		targetCls: $(this),
		type: 'yyyy-mm-dd',
		wday: 2
	})
});